package com.yami.shop.multishop.controller;


import com.google.common.collect.Maps;
import com.yami.shop.bean.app.param.SendSmsParam;
import com.yami.shop.bean.enums.SendType;
import com.yami.shop.bean.model.ShopDetail;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.nft.common.service.NftGasDeployService;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.ShopDetailService;
import com.yami.shop.service.SmsLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Objects;

@RestController
@RequestMapping("/m/nftgas")
@Tag(name = "admin-能量值充值配置信息")
public class NftGasDeployController {

    @Autowired
    private NftGasDeployService nftGasDeployService;

    @Autowired
    private ShopDetailService shopDetailService;

    @Autowired
    private SmsLogService smsLogService;


    @GetMapping("/getGasDeployList")
    @Operation(summary = "前端能量充值配置列表", description = "前端能量充值配置列表")
    public ServerResponseEntity<HashMap<Object,Object>> getGasDeployList(@RequestParam("chain") String chain) {
        ShopDetail shopDetail = shopDetailService.getById(SecurityUtils.getShopUser().getShopId());
        return ServerResponseEntity.success(nftGasDeployService.getShopGasDeployList(shopDetail,chain));
    }

    @GetMapping("/sendCode")
    @Operation(summary =  "发送验证码")
    public ServerResponseEntity<Void> sendLoginCode(@Valid @RequestParam("mobile") String mobile) {
        ShopDetail shopDetail = shopDetailService.getById(SecurityUtils.getShopUser().getShopId());
        if (Objects.isNull(mobile)) {
            // 手机号不能为空
            throw new YamiShopBindException("yami.shop.phone.no.exist");
        }
        smsLogService.sendSms(SendType.VALID, shopDetail.getUserId(), mobile, Maps.newHashMap());
        return ServerResponseEntity.success();
    }
}
